package logic

import (
	"context"
	"errors"

	"tianji-network/service/gateway/api/internal/svc"
	"tianji-network/service/gateway/api/internal/types"
	"tianji-network/service/gateway/api/tools"
	"tianji-network/service/satellite/rpc/satellite"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetSatelliteAllLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetSatelliteAllLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSatelliteAllLogic {
	return &GetSatelliteAllLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetSatelliteAllLogic) GetSatelliteAll() (resp *types.SatelliteListReply, err error) {
	//查询所有的卫星
	satelliteProtoResp, err := l.svcCtx.SatelliteRpc.GetAll(l.ctx, &satellite.Empty{})
	if err != nil {
		return nil, errors.New(err.Error())
	}
	satelliteList := make([]types.SatelliteReply, 0)
	for _, one := range satelliteProtoResp.SatelliteList {
		satellite := tools.ProtoConvertToResp(one)
		satelliteList = append(satelliteList, *satellite)
	}
	return &types.SatelliteListReply{SatelliteList: satelliteList}, nil
}
